/**
* \file DGVConsole.cpp
*
* \brief This file defines the class for displaying messages in a DGVMain or DGVMainVTK classes as a docked widget using only Qt.
* \author Shekhar S. Chandra, 2008
*
* This file is part of DGV Library.
*
* DGV is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DGV is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DGV.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "DGVConsole.h"

DGVConsole::DGVConsole(QWidget *parent) : QDockWidget(parent)
{
    listDisplay = new QListWidget(this);

    setWidget(listDisplay);

    createConnections();
}

DGVConsole::~DGVConsole()
{
    //dtor
}

void DGVConsole::printError(QString error)
{
    QListWidgetItem *newItem = new QListWidgetItem(listDisplay);
    QBrush brush;

    newItem->setText(error);
    brush.setColor(Qt::darkRed);
    newItem->setForeground(brush);
    listDisplay->addItem(newItem);
    qApp->processEvents(); //!< Process Qt Events

    emit consoleChanged();
}

void DGVConsole::printWarning(QString warning)
{
    QListWidgetItem *newItem = new QListWidgetItem(listDisplay);
    QBrush brush;

    newItem->setText(warning);
    brush.setColor(Qt::darkBlue);
    newItem->setForeground(brush);
    listDisplay->addItem(newItem);
    qApp->processEvents(); //!< Process Qt Events

    emit consoleChanged();
}

void DGVConsole::printInfo(QString info)
{
    listDisplay->addItem(info);
    qApp->processEvents(); //!< Process Qt Events

    emit consoleChanged();
}

void DGVConsole::printMessage(QString msg)
{
    QListWidgetItem *newItem = new QListWidgetItem(listDisplay);
    QBrush brush;

    newItem->setText(msg);
    brush.setColor(Qt::darkGreen);
    newItem->setForeground(brush);
    listDisplay->addItem(newItem);
    qApp->processEvents(); //!< Process Qt Events

    emit consoleChanged();
}

/*void DGVConsole::toFinalEntry()
{
    setCurrentRow(count()-1);
}*/

void DGVConsole::createConnections()
{
    connect(this, SIGNAL(consoleChanged()), this, SLOT(toFinalEntry()));
}
